package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.service.LabelService;

@RestController
@RequestMapping("/api/label")
@Api(value = "标签接口")
public class LabelController {
	@Autowired
	private LabelService labelService;
	
	/**
	 * 获取标签列表
	 * @return
	 */
	@RequestMapping(value="getLabelList",method = RequestMethod.GET)
	@ApiOperation(value="获取标签列表",httpMethod="GET",notes="获取标签列表")
	public Map<String, Object>getLabelList(){
		return labelService.getList();
	}
	
	
	/**
	 * 批量增加标签
	 * @param tags
	 * @return
	 */
	@RequestMapping(value="addBatch",method = RequestMethod.POST)
	@ApiOperation(value="批量增加标签",httpMethod="POST",notes="批量增加标签")
	public Object addBatch(@ApiParam(value="批量添加标签，用逗号进行分割",required=true)
	@RequestParam(value="tags",required=true)String tags,HttpServletRequest request){
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId =  userInfo.get("userId").toString();
		return labelService.addBatch(tags, userId);
	}
	
	/**
	 * 修改标签
	 * @param tags
	 * @param oldTagId
	 * @return
	 */
	@RequestMapping(value="updateBatch",method = RequestMethod.POST)
	@ApiOperation(value="修改标签",httpMethod="POST",notes="修改标签")
	public Object updateBatch(@ApiParam(
			value="批量添加标签，用逗号进行分割",required=true)@RequestParam(value="tags",required=true)String tags,
			@ApiParam(value="旧的标签ids，用逗号进行分割",required=true)@RequestParam(value="oldTagId",required=true)String oldTagId,
			HttpServletRequest request){
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId =  userInfo.get("userId").toString();
		return labelService.updateBatch(tags, oldTagId,userId);
	}
	

}
